{layout name="layouts/admin" /}
<!-- jQuery 2.1.4 -->
{js href="/static/admin/plugins/jQuery/jquery-1.9.1.min.js" /}
<div class="panel-heading">{$depdetail.id?"编辑":"添加"}{$depdetail.data_type?"疾病":"科室"}</div>
<div class="panel-body">
    <form action="/wechatgroup/doAddDep" method="POST">
        <div class="box-body">


            <div class="form-group">
                <input type="hidden" name="datatype" value="{$depdetail.data_type}"/>
                <label>选择父级大类</label>
                <select name="{$depdetail.data_type?'':'fatherid'}" class="form-control" id="fdepid" onchange="datachild()">
                    <option value="0" {$depdetail.father_id==0?"selected":""}>一级大类</option>
                    {foreach $fdeps as $item}
                    <option value="{$item.id}" {$item.id==$depdetail.father_id?"selected":""}>{$item.dep_name}</option>
                    {/foreach}
                </select>
            </div>
            {if $depdetail.data_type}
            <div class="form-group">
                <label>选择二级大类</label>
            <select name="fatherid" class="form-control" id="twodep">
                <option value="0" {$depdetail.tfdepid==0?"selected":""}>二级大类</option>
                {if $tfdeps}
                {foreach $tfdeps as $item}
                <option value="{$item.id}" {$item.id==$depdetail.tfdepid?"selected":""}>{$item.dep_name}</option>
                {/foreach}
                {/if}
            </select>
            </div>
            {/if}
            <div class="form-group">
                <label>{$depdetail.data_type?"疾病":"科室"}名称</label>
                <input type="hidden" name="id" value="{$depdetail.id|default=0}"/>
                <input type="text" name="depname" value="{$depdetail.dep_name|default=''}" class="form-control" placeholder="添加{$depdetail.data_type?"疾病":"科室"}名称">
            </div>


            <div class="form-group">
                <button type="submit" class="btn btn-primary">确认保存</button>
            </div>
        </div>
    </form>
</div>

<script>
    function datachild() {
        var dataid=$("#fdepid").val();
        var up = $("#twodep");

        $.ajax({
            type: "POST",
            url: "/wechatgroup/datachange",
            data: "datatype=0&dataid=" + dataid,
            success: function (msg) {
                var ms=eval('('+msg+')');
                $("option",up).remove(); //清空原有的选项
                $.each(ms,function(index,array){
                    var option = "<option value='"+array['id']+"'>"+array['dep_name']+"</option>";
                    up.append(option);
                });

            }
        });
    }
</script>